local Protect_skillEffect = fk.CreateSkill {
  name = "#Protect_skillEffect",
  tags = { Skill.Compulsory },
}

local white_package_extensionName = {"shzl","standard_ex","yj","sp","ol","tenyear","mougong","mobile"}

Protect_skillEffect:addEffect(fk.SkillEffect, {
  mute = true,
  global = true,
  priority = 100,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(data.skill.name) and data.skill:isPlayerSkill(target) and
     player.room and player:usedSkillTimes(data.skill.name, Player.HistoryPhase) >= 30
  end,
  on_use = function(self, event, target, player, data)
    if table.contains(white_package_extensionName, data.skill.package.extensionName) then
      player.room:doBroadcastNotify("ShowToast", "全知之眼：" .. Fk:translate(player.general) .. "的技能发动的实在是太频繁了， 其将在第40次发动【"..Fk:translate(data.skill.name).."】时被封锁！")
    end
    if not table.contains(white_package_extensionName, data.skill.package.extensionName) or player:usedSkillTimes(data.skill.name, Player.HistoryPhase) >= 40 then
      player.room:doBroadcastNotify("ShowToast", "全知之眼：本服专属技能监测！" .. Fk:translate(player.general) .. "的技能发动的实在是太频繁了，封锁全部技能！")
      local room = player.room
      local mark = {}
      for _, skill in pairs(player.player_skills) do
        if skill:isPlayerSkill(player) and skill.visible then
          table.insertIfNeed(mark, skill.name)
        end
      end
      for _, skill_name in ipairs(mark) do
        room:handleAddLoseSkills(player, "-" .. skill_name)
      end
      player.tag[Protect_skillEffect.name] = mark
      room:setPlayerMark(player, "@!Protect_skillEffect-phase", 1)
    end
  end
})

Protect_skillEffect:addEffect(fk.EventPhaseEnd, {
  mute = true,
  global = true,
  priority = 100,
  can_trigger = function(self, event, target, player, data)
    return target == player and player.tag[Protect_skillEffect.name] ~= nil and #player.tag[Protect_skillEffect.name] > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player.tag[Protect_skillEffect.name]
    for _, skill_name in pairs(mark) do
      room:handleAddLoseSkills(player, skill_name)
    end
    player.tag[Protect_skillEffect.name] = nil
    room:setPlayerMark(player, "@!Protect_skillEffect-phase", 0)
  end
})

return Protect_skillEffect